from mpi4py import MPI
import numpy as np
import sys
#import copy

sys.path.append('../../../')

from craft_all_five import bone, x1one, x2one,x3one, x4one, x5one, x6one, x7one, x8one, x9one, x10one, x11one, x12one, y1one, y2one, y3one, y4one, y5one

#from globalf import *
from splitglo import *
from neuralnet.shareglob import *

def coeffallfun(ndiscrete,ncb, xx,coeffall, delta, startd):
    #         mpin=int(ndiscrete/(size/nsplit))
    #  here mpi_split is used, where other parts only use mpi
    mpinsub = int(ndiscrete / (size / nsplit))
    submpi = int(ndiscrete / nsplit)

    sumtmax = 1. - startd
    sumtmin = startd * ncb

    for i1 in range(mpinsub):
        xx[0][i1] = startd + delta * (new_rank * mpinsub + i1)
        for i2 in range(submpi):
            xx[1][i2] = startd + delta * (color * submpi + i2)
            for i3 in range(ndiscrete):
              xx[2][i3] = startd + delta * i3
              if(ncb==4):
                 sumt=xx[0][i1]+xx[1][i2] +xx[2][i3]# +xx[3][i4]# + xx[4][i5] + xx[5][i6] + xx[6][i7] + xx[7][i8] + xx[8][i9]
  
                 if((sumt < sumtmax) and (sumt > sumtmin)):
                   xxpart=1.- sumt
                   coefftmp=np.array([xx[0][i1],xx[1][i2],xx[2][i3],xxpart])
              
                   coeffall.append(coefftmp)
              if(ncb>4):

                for i4 in range(ndiscrete):
                  xx[3][i4] = startd + delta * i4
                  if(ncb==5):
                     sumt=xx[0][i1]+xx[1][i2] +xx[2][i3] +xx[3][i4]# + xx[4][i5] + xx[5][i6] + xx[6][i7] + xx[7][i8] + xx[8][i9]
  
                     if((sumt < sumtmax) and (sumt > sumtmin)):
                       xxpart=1.- sumt
                       coefftmp=np.array([xx[0][i1],xx[1][i2],xx[2][i3],xx[3][i4],xxpart])
                  
                       coeffall.append(coefftmp)
                  if(ncb>5):

                    for i5 in range(ndiscrete):
                      xx[4][i5] = startd + delta * i5
                      if(ncb==6):
                        sumt=xx[0][i1]+xx[1][i2] +xx[2][i3] +xx[3][i4] + xx[4][i5]# + xx[5][i6] + xx[6][i7] + xx[7][i8] + xx[8][i9]
  
                        if((sumt < sumtmax) and (sumt > sumtmin)):
                          xxpart=1.- sumt
                          coefftmp=np.array([xx[0][i1],xx[1][i2],xx[2][i3],xx[3][i4],xx[4][i5],xxpart])
               
                          coeffall.append(coefftmp)

                      if(ncb>6):

                        for i6 in range(ndiscrete):
                          xx[5][i6] = startd + delta * i6
                          if(ncb==7):
                             sumt=xx[0][i1]+xx[1][i2] +xx[2][i3] +xx[3][i4] + xx[4][i5] + xx[5][i6]# + xx[6][i7] + xx[7][i8] + xx[8][i9]
  
                             if((sumt < sumtmax) and (sumt > sumtmin)):
                               xxpart=1.- sumt
                               coefftmp=np.array([xx[0][i1],xx[1][i2],xx[2][i3],xx[3][i4],xx[4][i5],xx[5][i6],xxpart])
                 
                               coeffall.append(coefftmp)
                          if(ncb>7):

                            for i7 in range(ndiscrete):
                              xx[6][i7] = startd + delta * i7
                              if(ncb==8):
                                 sumt=xx[0][i1]+xx[1][i2] +xx[2][i3] +xx[3][i4] + xx[4][i5] + xx[5][i6] + xx[6][i7]# + xx[7][i8] + xx[8][i9]
  
                                 if((sumt < sumtmax) and (sumt > sumtmin)):
                                   xxpart=1.- sumt
                                   coefftmp=np.array([xx[0][i1],xx[1][i2],xx[2][i3],xx[3][i4],xx[4][i5],xx[5][i6],xx[6][i7],xxpart])
                  
                                   coeffall.append(coefftmp)

                              if(ncb>8):

                                for i8 in range(ndiscrete):
                                  xx[7][i8] = startd + delta * i8
                                  if(ncb==9):
                                     sumt=xx[0][i1]+xx[1][i2] +xx[2][i3] +xx[3][i4] + xx[4][i5] + xx[5][i6] + xx[6][i7] + xx[7][i8]# + xx[8][i9]
  
                                     if((sumt < sumtmax) and (sumt > sumtmin)):
                                       xxpart=1.- sumt
                                       coefftmp=np.array([xx[0][i1],xx[1][i2],xx[2][i3],xx[3][i4],xx[4][i5],xx[5][i6],xx[6][i7],xx[7][i8],xxpart])
                  
                                       coeffall.append(coefftmp)

                                  if(ncb>9):

                                    for i9 in range(ndiscrete):
                                        xx[8][i9] = startd + delta * i9
                                        if (ncb == 10):
                                            sumt = xx[0][i1] + xx[1][i2] + xx[2][i3] + xx[3][i4] + xx[4][i5] + xx[5][
                                                i6] + xx[6][i7] + xx[7][i8] + xx[8][i9]

                                            if ((sumt < sumtmax) and (sumt > sumtmin)):
                                                xxpart = 1. - sumt
                                                coefftmp = np.array(
                                                    [xx[0][i1], xx[1][i2], xx[2][i3], xx[3][i4], xx[4][i5], xx[5][i6],
                                                     xx[6][i7], xx[7][i8], xx[8][i9], xxpart])

                                                coeffall.append(coefftmp)

                                        if (ncb > 10):
                                            for i10 in range(ndiscrete):
                                                xx[9][i10] = startd + delta * i10
                                                if (ncb == 11):
                                                    sumt = xx[0][i1] + xx[1][i2] + xx[2][i3] + xx[3][i4] + xx[4][i5] + \
                                                           xx[5][i6] + xx[6][i7] + xx[7][i8] + xx[8][i9] + xx[9][i10]

                                                    if ((sumt < sumtmax) and (sumt > sumtmin)):
                                                        xxpart = 1. - sumt
                                                        coefftmp = np.array(
                                                            [xx[0][i1], xx[1][i2], xx[2][i3], xx[3][i4], xx[4][i5],
                                                             xx[5][i6], xx[6][i7], xx[7][i8], xx[8][i9], xx[9][i10],
                                                             xxpart])

                                                        coeffall.append(coefftmp)

                                                if (ncb > 11):
                                                    for i11 in range(ndiscrete):
                                                        xx[10][i11] = startd + delta * i11
                                                        if (ncb == 12):
                                                            sumt = xx[0][i1] + xx[1][i2] + xx[2][i3] + xx[3][i4] + \
                                                                   xx[4][i5] + xx[5][i6] + xx[6][i7] + xx[7][i8] + \
                                                                   xx[8][i9] + xx[9][i10] + xx[10][i11]

                                                            if ((sumt < sumtmax) and (sumt > sumtmin)):
                                                                xxpart = 1. - sumt
                                                                coefftmp = np.array(
                                                                    [xx[0][i1], xx[1][i2], xx[2][i3], xx[3][i4],
                                                                     xx[4][i5], xx[5][i6], xx[6][i7], xx[7][i8],
                                                                     xx[8][i9], xx[9][i10], xx[10][i11], xxpart])

                                                                coeffall.append(coefftmp)

                                                        if (ncb > 12):
                                                            for i12 in range(ndiscrete):
                                                                xx[11][i12] = startd + delta * i12
                                                                if (ncb == 13):
                                                                    sumt = xx[0][i1] + xx[1][i2] + xx[2][i3] + xx[3][
                                                                        i4] + xx[4][i5] + xx[5][i6] + xx[6][i7] + xx[7][
                                                                               i8] + xx[8][i9] + xx[9][i10] + xx[10][
                                                                               i11] + xx[11][i12]

                                                                    if ((sumt < sumtmax) and (sumt > sumtmin)):
                                                                        xxpart = 1. - sumt
                                                                        coefftmp = np.array(
                                                                            [xx[0][i1], xx[1][i2], xx[2][i3], xx[3][i4],
                                                                             xx[4][i5], xx[5][i6], xx[6][i7], xx[7][i8],
                                                                             xx[8][i9], xx[9][i10], xx[10][i11],
                                                                             xx[11][i12], xxpart])

                                                                        coeffall.append(coefftmp)

                                                                if (ncb > 13):
                                                                    for i13 in range(ndiscrete):
                                                                        xx[12][i13] = startd + delta * i13
                                                                        if (ncb == 14):
                                                                            sumt = xx[0][i1] + xx[1][i2] + xx[2][i3] + \
                                                                                   xx[3][i4] + xx[4][i5] + xx[5][i6] + \
                                                                                   xx[6][i7] + xx[7][i8] + xx[8][i9] + \
                                                                                   xx[9][i10] + xx[10][i11] + xx[11][
                                                                                       i12] + xx[12][i13]

                                                                            if ((sumt < sumtmax) and (sumt > sumtmin)):
                                                                                xxpart = 1. - sumt
                                                                                coefftmp = np.array(
                                                                                    [xx[0][i1], xx[1][i2], xx[2][i3],
                                                                                     xx[3][i4], xx[4][i5], xx[5][i6],
                                                                                     xx[6][i7], xx[7][i8], xx[8][i9],
                                                                                     xx[9][i10], xx[10][i11],
                                                                                     xx[11][i12], xx[12][i13], xxpart])

                                                                                coeffall.append(coefftmp)

                                                                        if (ncb > 14):
                                                                            for i14 in range(ndiscrete):
                                                                                xx[13][i14] = startd + delta * i14
                                                                                if (ncb == 15):
                                                                                    sumt = xx[0][i1] + xx[1][i2] + \
                                                                                           xx[2][i3] + xx[3][i4] + \
                                                                                           xx[4][i5] + xx[5][i6] + \
                                                                                           xx[6][i7] + xx[7][i8] + \
                                                                                           xx[8][i9] + xx[9][i10] + \
                                                                                           xx[10][i11] + xx[11][i12] + \
                                                                                           xx[12][i13] + xx[13][i14]

                                                                                    if ((sumt < sumtmax) and (
                                                                                            sumt > sumtmin)):
                                                                                        xxpart = 1. - sumt
                                                                                        coefftmp = np.array(
                                                                                            [xx[0][i1], xx[1][i2],
                                                                                             xx[2][i3], xx[3][i4],
                                                                                             xx[4][i5], xx[5][i6],
                                                                                             xx[6][i7], xx[7][i8],
                                                                                             xx[8][i9], xx[9][i10],
                                                                                             xx[10][i11], xx[11][i12],
                                                                                             xx[12][i13], xx[13][i14],
                                                                                             xxpart])

                                                                                        coeffall.append(coefftmp)

                                                                                if (ncb > 15):
                                                                                    for i15 in range(ndiscrete):
                                                                                        xx[14][
                                                                                            i15] = startd + delta * i15
                                                                                        if (ncb == 16):
                                                                                            sumt = xx[0][i1] + xx[1][
                                                                                                i2] + xx[2][i3] + xx[3][
                                                                                                       i4] + xx[4][i5] + \
                                                                                                   xx[5][i6] + xx[6][
                                                                                                       i7] + xx[7][i8] + \
                                                                                                   xx[8][i9] + xx[9][
                                                                                                       i10] + xx[10][
                                                                                                       i11] + xx[11][
                                                                                                       i12] + xx[12][
                                                                                                       i13] + xx[13][
                                                                                                       i14] + xx[14][
                                                                                                       i15]

                                                                                            if ((sumt < sumtmax) and (
                                                                                                    sumt > sumtmin)):
                                                                                                xxpart = 1. - sumt
                                                                                                coefftmp = np.array(
                                                                                                    [xx[0][i1],
                                                                                                     xx[1][i2],
                                                                                                     xx[2][i3],
                                                                                                     xx[3][i4],
                                                                                                     xx[4][i5],
                                                                                                     xx[5][i6],
                                                                                                     xx[6][i7],
                                                                                                     xx[7][i8],
                                                                                                     xx[8][i9],
                                                                                                     xx[9][i10],
                                                                                                     xx[10][i11],
                                                                                                     xx[11][i12],
                                                                                                     xx[12][i13],
                                                                                                     xx[13][i14],
                                                                                                     xx[14][i15],
                                                                                                     xxpart])

                                                                                                coeffall.append(
                                                                                                    coefftmp)

                                                                                        if (ncb > 16):
                                                                                            for i16 in range(ndiscrete):
                                                                                                xx[15][
                                                                                                    i16] = startd + delta * i16
                                                                                                if (ncb == 17):
                                                                                                    sumt = xx[0][i1] + \
                                                                                                           xx[1][i2] + \
                                                                                                           xx[2][i3] + \
                                                                                                           xx[3][i4] + \
                                                                                                           xx[4][i5] + \
                                                                                                           xx[5][i6] + \
                                                                                                           xx[6][i7] + \
                                                                                                           xx[7][i8] + \
                                                                                                           xx[8][i9] + \
                                                                                                           xx[9][i10] + \
                                                                                                           xx[10][i11] + \
                                                                                                           xx[11][i12] + \
                                                                                                           xx[12][i13] + \
                                                                                                           xx[13][i14] + \
                                                                                                           xx[14][i15] + \
                                                                                                           xx[15][i16]

                                                                                                    if ((
                                                                                                            sumt < sumtmax) and (
                                                                                                            sumt > sumtmin)):
                                                                                                        xxpart = 1. - sumt
                                                                                                        coefftmp = np.array(
                                                                                                            [xx[0][i1],
                                                                                                             xx[1][i2],
                                                                                                             xx[2][i3],
                                                                                                             xx[3][i4],
                                                                                                             xx[4][i5],
                                                                                                             xx[5][i6],
                                                                                                             xx[6][i7],
                                                                                                             xx[7][i8],
                                                                                                             xx[8][i9],
                                                                                                             xx[9][i10],
                                                                                                             xx[10][
                                                                                                                 i11],
                                                                                                             xx[11][
                                                                                                                 i12],
                                                                                                             xx[12][
                                                                                                                 i13],
                                                                                                             xx[13][
                                                                                                                 i14],
                                                                                                             xx[14][
                                                                                                                 i15],
                                                                                                             xx[15][
                                                                                                                 i16],
                                                                                                             xxpart])

                                                                                                        coeffall.append(
                                                                                                            coefftmp)

                                                                                                if (ncb > 17):
                                                                                                    for i17 in range(
                                                                                                            ndiscrete):
                                                                                                        xx[16][
                                                                                                            i17] = startd + delta * i17
                                                                                                        if (ncb == 18):
                                                                                                            sumt = \
                                                                                                                xx[0][
                                                                                                                    i1] + \
                                                                                                                xx[1][
                                                                                                                    i2] + \
                                                                                                                xx[2][
                                                                                                                    i3] + \
                                                                                                                xx[3][
                                                                                                                    i4] + \
                                                                                                                xx[4][
                                                                                                                    i5] + \
                                                                                                                xx[5][
                                                                                                                    i6] + \
                                                                                                                xx[6][
                                                                                                                    i7] + \
                                                                                                                xx[7][
                                                                                                                    i8] + \
                                                                                                                xx[8][
                                                                                                                    i9] + \
                                                                                                                xx[9][
                                                                                                                    i10] + \
                                                                                                                xx[10][
                                                                                                                    i11] + \
                                                                                                                xx[11][
                                                                                                                    i12] + \
                                                                                                                xx[12][
                                                                                                                    i13] + \
                                                                                                                xx[13][
                                                                                                                    i14] + \
                                                                                                                xx[14][
                                                                                                                    i15] + \
                                                                                                                xx[15][
                                                                                                                    i16] + \
                                                                                                                xx[16][
                                                                                                                    i17]

                                                                                                            if ((
                                                                                                                    sumt < sumtmax) and (
                                                                                                                    sumt > sumtmin)):
                                                                                                                xxpart = 1. - sumt
                                                                                                                coefftmp = np.array(
                                                                                                                    [xx[
                                                                                                                         0][
                                                                                                                         i1],
                                                                                                                     xx[
                                                                                                                         1][
                                                                                                                         i2],
                                                                                                                     xx[
                                                                                                                         2][
                                                                                                                         i3],
                                                                                                                     xx[
                                                                                                                         3][
                                                                                                                         i4],
                                                                                                                     xx[
                                                                                                                         4][
                                                                                                                         i5],
                                                                                                                     xx[
                                                                                                                         5][
                                                                                                                         i6],
                                                                                                                     xx[
                                                                                                                         6][
                                                                                                                         i7],
                                                                                                                     xx[
                                                                                                                         7][
                                                                                                                         i8],
                                                                                                                     xx[
                                                                                                                         8][
                                                                                                                         i9],
                                                                                                                     xx[
                                                                                                                         9][
                                                                                                                         i10],
                                                                                                                     xx[
                                                                                                                         10][
                                                                                                                         i11],
                                                                                                                     xx[
                                                                                                                         11][
                                                                                                                         i12],
                                                                                                                     xx[
                                                                                                                         12][
                                                                                                                         i13],
                                                                                                                     xx[
                                                                                                                         13][
                                                                                                                         i14],
                                                                                                                     xx[
                                                                                                                         14][
                                                                                                                         i15],
                                                                                                                     xx[
                                                                                                                         15][
                                                                                                                         i16],
                                                                                                                     xx[
                                                                                                                         16][
                                                                                                                         i17],
                                                                                                                     xxpart])

                                                                                                                coeffall.append(
                                                                                                                    coefftmp)

                                                                                                        if (ncb > 18):
                                                                                                            for i18 in range(
                                                                                                                    ndiscrete):
                                                                                                                xx[17][
                                                                                                                    i18] = startd + delta * i18
                                                                                                                if (
                                                                                                                        ncb == 19):
                                                                                                                    sumt = \
                                                                                                                        xx[
                                                                                                                            0][
                                                                                                                            i1] + \
                                                                                                                        xx[
                                                                                                                            1][
                                                                                                                            i2] + \
                                                                                                                        xx[
                                                                                                                            2][
                                                                                                                            i3] + \
                                                                                                                        xx[
                                                                                                                            3][
                                                                                                                            i4] + \
                                                                                                                        xx[
                                                                                                                            4][
                                                                                                                            i5] + \
                                                                                                                        xx[
                                                                                                                            5][
                                                                                                                            i6] + \
                                                                                                                        xx[
                                                                                                                            6][
                                                                                                                            i7] + \
                                                                                                                        xx[
                                                                                                                            7][
                                                                                                                            i8] + \
                                                                                                                        xx[
                                                                                                                            8][
                                                                                                                            i9] + \
                                                                                                                        xx[
                                                                                                                            9][
                                                                                                                            i10] + \
                                                                                                                        xx[
                                                                                                                            10][
                                                                                                                            i11] + \
                                                                                                                        xx[
                                                                                                                            11][
                                                                                                                            i12] + \
                                                                                                                        xx[
                                                                                                                            12][
                                                                                                                            i13] + \
                                                                                                                        xx[
                                                                                                                            13][
                                                                                                                            i14] + \
                                                                                                                        xx[
                                                                                                                            14][
                                                                                                                            i15] + \
                                                                                                                        xx[
                                                                                                                            15][
                                                                                                                            i16] + \
                                                                                                                        xx[
                                                                                                                            16][
                                                                                                                            i17] + \
                                                                                                                        xx[
                                                                                                                            17][
                                                                                                                            i18]

                                                                                                                    if (
                                                                                                                            (
                                                                                                                                    sumt < sumtmax) and (
                                                                                                                            sumt > sumtmin)):
                                                                                                                        xxpart = 1. - sumt
                                                                                                                        coefftmp = np.array(
                                                                                                                            [
                                                                                                                                xx[
                                                                                                                                    0][
                                                                                                                                    i1],
                                                                                                                                xx[
                                                                                                                                    1][
                                                                                                                                    i2],
                                                                                                                                xx[
                                                                                                                                    2][
                                                                                                                                    i3],
                                                                                                                                xx[
                                                                                                                                    3][
                                                                                                                                    i4],
                                                                                                                                xx[
                                                                                                                                    4][
                                                                                                                                    i5],
                                                                                                                                xx[
                                                                                                                                    5][
                                                                                                                                    i6],
                                                                                                                                xx[
                                                                                                                                    6][
                                                                                                                                    i7],
                                                                                                                                xx[
                                                                                                                                    7][
                                                                                                                                    i8],
                                                                                                                                xx[
                                                                                                                                    8][
                                                                                                                                    i9],
                                                                                                                                xx[
                                                                                                                                    9][
                                                                                                                                    i10],
                                                                                                                                xx[
                                                                                                                                    10][
                                                                                                                                    i11],
                                                                                                                                xx[
                                                                                                                                    11][
                                                                                                                                    i12],
                                                                                                                                xx[
                                                                                                                                    12][
                                                                                                                                    i13],
                                                                                                                                xx[
                                                                                                                                    13][
                                                                                                                                    i14],
                                                                                                                                xx[
                                                                                                                                    14][
                                                                                                                                    i15],
                                                                                                                                xx[
                                                                                                                                    15][
                                                                                                                                    i16],
                                                                                                                                xx[
                                                                                                                                    16][
                                                                                                                                    i17],
                                                                                                                                xx[
                                                                                                                                    17][
                                                                                                                                    i18],
                                                                                                                                xxpart])

                                                                                                                        coeffall.append(
                                                                                                                            coefftmp)

                                                                                                                if (
                                                                                                                        ncb > 19):
                                                                                                                    for i19 in range(
                                                                                                                            ndiscrete):
                                                                                                                        xx[
                                                                                                                            18][
                                                                                                                            i19] = startd + delta * i19
                                                                                                                        if (
                                                                                                                                ncb == 20):
                                                                                                                            sumt = \
                                                                                                                                xx[
                                                                                                                                    0][
                                                                                                                                    i1] + \
                                                                                                                                xx[
                                                                                                                                    1][
                                                                                                                                    i2] + \
                                                                                                                                xx[
                                                                                                                                    2][
                                                                                                                                    i3] + \
                                                                                                                                xx[
                                                                                                                                    3][
                                                                                                                                    i4] + \
                                                                                                                                xx[
                                                                                                                                    4][
                                                                                                                                    i5] + \
                                                                                                                                xx[
                                                                                                                                    5][
                                                                                                                                    i6] + \
                                                                                                                                xx[
                                                                                                                                    6][
                                                                                                                                    i7] + \
                                                                                                                                xx[
                                                                                                                                    7][
                                                                                                                                    i8] + \
                                                                                                                                xx[
                                                                                                                                    8][
                                                                                                                                    i9] + \
                                                                                                                                xx[
                                                                                                                                    9][
                                                                                                                                    i10] + \
                                                                                                                                xx[
                                                                                                                                    10][
                                                                                                                                    i11] + \
                                                                                                                                xx[
                                                                                                                                    11][
                                                                                                                                    i12] + \
                                                                                                                                xx[
                                                                                                                                    12][
                                                                                                                                    i13] + \
                                                                                                                                xx[
                                                                                                                                    13][
                                                                                                                                    i14] + \
                                                                                                                                xx[
                                                                                                                                    14][
                                                                                                                                    i15] + \
                                                                                                                                xx[
                                                                                                                                    15][
                                                                                                                                    i16] + \
                                                                                                                                xx[
                                                                                                                                    16][
                                                                                                                                    i17] + \
                                                                                                                                xx[
                                                                                                                                    17][
                                                                                                                                    i18] + \
                                                                                                                                xx[
                                                                                                                                    18][
                                                                                                                                    i19]

                                                                                                                            if (
                                                                                                                                    (
                                                                                                                                            sumt < sumtmax) and (
                                                                                                                                    sumt > sumtmin)):
                                                                                                                                xxpart = 1. - sumt
                                                                                                                                coefftmp = np.array(
                                                                                                                                    [
                                                                                                                                        xx[
                                                                                                                                            0][
                                                                                                                                            i1],
                                                                                                                                        xx[
                                                                                                                                            1][
                                                                                                                                            i2],
                                                                                                                                        xx[
                                                                                                                                            2][
                                                                                                                                            i3],
                                                                                                                                        xx[
                                                                                                                                            3][
                                                                                                                                            i4],
                                                                                                                                        xx[
                                                                                                                                            4][
                                                                                                                                            i5],
                                                                                                                                        xx[
                                                                                                                                            5][
                                                                                                                                            i6],
                                                                                                                                        xx[
                                                                                                                                            6][
                                                                                                                                            i7],
                                                                                                                                        xx[
                                                                                                                                            7][
                                                                                                                                            i8],
                                                                                                                                        xx[
                                                                                                                                            8][
                                                                                                                                            i9],
                                                                                                                                        xx[
                                                                                                                                            9][
                                                                                                                                            i10],
                                                                                                                                        xx[
                                                                                                                                            10][
                                                                                                                                            i11],
                                                                                                                                        xx[
                                                                                                                                            11][
                                                                                                                                            i12],
                                                                                                                                        xx[
                                                                                                                                            12][
                                                                                                                                            i13],
                                                                                                                                        xx[
                                                                                                                                            13][
                                                                                                                                            i14],
                                                                                                                                        xx[
                                                                                                                                            14][
                                                                                                                                            i15],
                                                                                                                                        xx[
                                                                                                                                            15][
                                                                                                                                            i16],
                                                                                                                                        xx[
                                                                                                                                            16][
                                                                                                                                            i17],
                                                                                                                                        xx[
                                                                                                                                            17][
                                                                                                                                            i18],
                                                                                                                                        xx[
                                                                                                                                            18][
                                                                                                                                            i19],
                                                                                                                                        xxpart])

                                                                                                                                coeffall.append(
                                                                                                                                    coefftmp)
#    return delta, startd
#    startd = startd
#         print('len(coeffall) in function = ', len(coeffall))
#         print('coeffall in function = ', coeffall[0])
